<?php
/**
 * run with command 
 * php workermain_start.php start/stop/reload/restart/status/connections [-d]
 */

ini_set('display_errors', 'on');
use Workerman\Worker;

if(strpos(strtolower(PHP_OS), 'win') === 0)
{
    exit("start.php not support windows, please use start_for_win.bat\n");
}

// 检查扩展
if(!extension_loaded('pcntl'))
{
    exit("Please install pcntl extension. See http://doc3.workerman.net/appendices/install-extension.html\n");
}

if(!extension_loaded('posix'))
{
    exit("Please install posix extension. See http://doc3.workerman.net/appendices/install-extension.html\n");
}

// 标记是全局启动
define('GLOBAL_START', 1);

require(__DIR__ . '/../../vendor/autoload.php');
require(__DIR__ . '/../../vendor/yiisoft/yii2/Yii.php');
require(__DIR__ . '/../../common/config/bootstrap.php');
require(__DIR__ . '/../config/bootstrap.php');

$config = yii\helpers\ArrayHelper::merge(
    require(__DIR__ . '/../../common/config/main.php'),
    require(__DIR__ . '/../../common/config/main-local.php'),
    require(__DIR__ . '/../config/main.php'),
    require(__DIR__ . '/../config/main-local.php')
    );

(new yii\web\Application($config))->init();

// 加载指定的start*.php，启动服务
//foreach(glob(__DIR__.'/workermanproject/*/start*.php') as $start_file)
//{
//    require_once $start_file;
//}

// park相关workerman服务
require_once __DIR__.'/start_businessworker.php';
require_once __DIR__.'/start_gateway_websocket.php';
require_once __DIR__.'/start_register.php';

// 运行所有服务
Worker::runAll();